package com.warren.controller;

import com.warren.common.ResponseResult;
import com.warren.config.AliyunConfig;
import com.warren.entity.TmWxmpBanner;
import com.warren.service.BannerService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.system.ApplicationPid;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.UUID;

/**
 * @version V1.0
 * @Description:
 * @author: warren
 * @date: 2022/7/14$ 22:07$
 */
@RequestMapping("/banner")
@RestController
@Api("banner api")
public class BannerController {
    @Autowired
    BannerService bannerService;

    @Autowired
    AliyunConfig aliyunConfig;

    @Value("${aliyun.key:111}")
    private String value;

    @Value("${server.port:8080}")
    private String port;

    @Value("${server.port}")
    private String port1;

    @GetMapping("/list")
    public ResponseResult getList() {
        List<TmWxmpBanner> list = bannerService.getList();
        return ResponseResult.success(list);
    }

    @GetMapping("/get/{id}")
    public ResponseResult view(@PathVariable("id") Long id) {
        TmWxmpBanner tmWxmpBanner = bannerService.view(id);
        return ResponseResult.success(tmWxmpBanner);
    }

    @GetMapping("/getValue")
    public ResponseResult get(HttpServletRequest request, HttpServletResponse response) {
        System.out.println(port);
        System.out.println(port1);
        UUID uuid = UUID.randomUUID();
        response.addHeader("key1", uuid.toString());
        response.setContentType("application/xml");
        return ResponseResult.success(value + port);
    }

    @GetMapping("/getAliyunConfig")
    public ResponseResult getAliyunConfig() {
        System.out.println(aliyunConfig);
        return ResponseResult.success("ok");
    }
}
